<?php

namespace App\Admin\Controllers;

use App\Models\KaoqinLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Support\Facades\DB;

class KaoqinLogController extends AdminController
{

    protected $title = '打卡记录明细';
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new KaoqinLog(), function (Grid $grid) {
//            $grid->disableActions();
            $grid->disableViewButton();
            $grid->disableCreateButton();

            $grid->number();
            $grid->column('user_name','姓名');
            $grid->column('user_id','身份证号');
            $grid->column('sn','设备所在地')->display(function ($mac) {
                return DB::table('device_list')->where('sn',$mac)->value('engineering_name');
            })->limit('20');
            $grid->column('today_date','打卡日期');

            $grid->column('morning','上午')->display(function ($morning) {
                if($morning == 1){
                    return "<span style='color:blue'>已打卡</span>";
                }else{
                    return "<span style='color:red'>未打卡</span>";
                }
            });
            $grid->column('afternoon','下午')->display(function ($afternoon) {
                if($afternoon == 1){
                    return "<span style='color:blue'>已打卡</span>";
                }else{
                    return "<span style='color:red'>未打卡</span>";
                }
            });

            $grid->column('morning_time','上午打卡时间');
            $grid->column('afternoon_time','下午打卡时间');

//            $grid->column('created_at','打卡时间');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new KaoqinLog(), function (Show $show) {
            $show->field('id');
            $show->field('id_card');
            $show->field('mac');
            $show->field('check_time');
            $show->field('name');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new KaoqinLog(), function (Form $form) {
            $form->display('id');
//            $form->text('id_card');
//            $form->text('mac');
//            $form->text('check_time');
//            $form->text('name');
            $form->radio('morning','上午是否打卡')->options(['0' => '未打卡', '1'=> '已打卡'])->default('0');

            $form->radio('afternoon','下午是否打卡')->options(['0' => '未打卡', '1'=> '已打卡'])->default('0');



//            $form->display('created_at');
//            $form->display('updated_at');
        });
    }
}
